#!/bin/bash 
clear

MESSAGE='
==========================================================================
# 最近更新：2022-07-17
# 支持版本 Ubuntu 20
# 支持版本 python版本跟随操作系统，Ubuntu 20(Python3.8+)
# 作者: Bruce chou
# 支持: lcgyzsl@qq.com
#-------------------------------------------------------------------------------
# wget https://gitee.com/smjk/odoo15-install-script-for-ubuntu/blob/master/install_cn.sh
# 使用方法，直接在主机上执行以下指令
# sudo chmod +x ./install_cn.sh 
# ./install_cn.sh 

# 本脚本将安装Odoo到你的服务器上，一般而言，整个过程在3~5分钟完成 
# 由于国内下载 wkhtmltox_0.12.6-1 超慢，请自行下载上传到本文件同目录中安装快一点
# 如果要启用SSL NGINX访问请上传相关key及pem文件 至 当前目录下的ssl目录中
#-------------------------------------------------------------------------------
# 
# 
=========================================================================='
echo "$MESSAGE"
#--------------------------------------------------
# 变量定义
#--------------------------------------------------
# 当前目录
CURDIR=$(pwd)
# 要安装的ODOO版本号
OE_VERSION="15.0"
OE_PORT="8069"
OE_PORT_CHAT="8072"

IS_ENTERPRISE="False"
# 选择要安装的odoo版本
OE_TYPE="odoo15 github 社区版"

WEBSITE_NAME="erp.2rails.cn"

# Ubuntu的主版本号如 20
U_Version=$(lsb_release -r --short)
U_Version=${U_Version:0:2}

# 核心版本号 如 focal
UR_VERSION=$(lsb_release -c)
UR_VERSION=${VERSION#*Codename:}
 

OE_USER=$USER
OE_HOME="/home/${OE_USER}/odoo${OE_VERSION}"
 
# 安装 WKHTMLTOPDF，默认设置为 True ，如果已安装则设置为 False.
INSTALL_WKHTMLTOPDF="True"
# 中文字体相关 


OE_COMMUNITY_LATEST_15="http://nightly.odoocdn.com/15.0/nightly/deb/odoo_15.0.latest_all.deb"
# 如果要安装odoo企业版，则在此设置为 True

# 选择要安装的pg版本
OE_PG=""
# 选择是否要安装nginx，True安装，Fale不安装
OE_NGINX="False"
# NGINX SSL开启
OE_NGINX_SSL="False"

# 设置超管的用户名及密码
OE_SUPERADMIN="admin"
# 是否自动生成Odoo超管密码，如果为True则OE_SUPERADMIN变量的值为自动生成
GENERATE_RANDOM_PASSWORD="True"

# 设置 odoo 配置文件名
OE_CONFIG_FILE_NAME="odoo${OE_VERSION}.conf"

# WKHTMLTOPDF 下载链接，使用https后停用cdn，注意主机版本及 WKHTMLTOPDF的版本
WKHTMLTOX_X64="https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.$(lsb_release -c -s)_amd64.deb"
WKHTMLTOX_X32="https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.$(lsb_release -c -s)_i386.deb"
#https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-1/wkhtmltox_0.12.6-1.focal_amd64.deb
 
function _p()
{
    _len=$#
    _msg=$1
    _forecolor="31m" #31-35 红绿黄蓝粉
    _colorAlphy="1"
    if [ $_len > "1" ];then
        _forecolor="$2m"
    fi
    if [ $_len > "2" ];then
        _colorAlphy=$3
    fi
    echo -e "\e[${_colorAlphy};${_forecolor}${_msg}\e[0m"
}

if [ $GENERATE_RANDOM_PASSWORD="True" ]; then
    _p "* Generating random admin password"
    OE_SUPERADMIN=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)
fi
function S_1_ConfirmOdoo()
{
	_p "[Notice] Confirm Install - odoo 15 \nPlease select your odoo version: (1~9)" 31 1
	select selected in 'odoo15 github 社区版' 'Odoo 15 Community from odoo.com 远程社区版' 'Odoo 15 Community from local[odoo_15.0.latest_all.deb] 本地社区版' 'Odoo 15 Enterprise from local[odoo_15.0+e.latest_all.deb] 本地企业版' 'None(and Exit)' 
    do 
        [ "$selected"!='' ] &&  _p "[OK] You Selected: ${selected}\n" && OE_TYPE=$selected && return 0 
    done 
	S_1_ConfirmOdoo
}

function S_2_ConfirmPg()
{
	_p "[Notice] Confirm Install - Postgresql \nPlease select your version: "
	select selected in 'Postgresql 14' 'Postgresql 13' 'Postgresql 12.x [Recommend. OS default]' 'None' 
    do 
        break 
    done
	[ "$selected" != '' ] &&  _p "[OK] You Selected: ${selected}\n" && OE_PG=$selected && return 0
	S_2_ConfirmPg
}

function S_3_ConfirmNg()
{
	_p "[Notice] Confirm Install - Nginx for web forward: "
	select selected in 'Nginx for Odoo in port 80 or 443[Yes]' 'Odoo standalone in port 8069[No]' 
    do 
        break 
    done
	[ "$selected" != '' ] &&  _p "[OK] You Selected: ${selected}\n" && OE_NGINX=$selected && return 0
	S_3_ConfirmNg
}
 
#--------------------------------------------------
# 更新服务器，多数要人工干预，故可以注释
# 升级服务器到 ubuntu 20，不需要可以注释
#--------------------------------------------------
# _p "\n---- Update Server ----"
# apt install update-manager
# apt-get update && sudo apt-get dist-upgrade
# do-release-upgrade -d -m server -q
# sudo add-apt-repository universe
# sudo apt-get update
# sudo apt-get upgrade -y
#--------------------------------------------------
# End 更新服务器
#--------------------------------------------------


function S_7_CreateOdooConf()
{
    if [ -f /etc/${OE_CONFIG_FILE_NAME} ];then
        sudo rm -f   /etc/${OE_CONFIG_FILE_NAME}
    fi

    sudo touch /etc/${OE_CONFIG_FILE_NAME}
    _p "* Creating server config file"
    sudo su root -c "printf '[options] \n; This is the password that allows database operations:\n' > /etc/${OE_CONFIG_FILE_NAME}"
    # if [ $GENERATE_RANDOM_PASSWORD="True" ]; then
    #     _p "* Generating random admin password"
    #     OE_SUPERADMIN=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1)
    # fi
    sudo su root -c "printf 'admin_passwd=${OE_SUPERADMIN}\n' >> /etc/${OE_CONFIG_FILE_NAME}"
    if [ $OE_VERSION > "11.0" ];then
        sudo su root -c "printf 'http_port=${OE_PORT}\n' >> /etc/${OE_CONFIG_FILE_NAME}"
    else
        sudo su root -c "printf 'xmlrpc_port=${OE_PORT}\n' >> /etc/${OE_CONFIG_FILE_NAME}"
    fi

    sudo su root -c "printf 'db_user=$OE_USER\n' >> /etc/${OE_CONFIG_FILE_NAME}"
    sudo su root -c "printf 'db_host = False\n' >> /etc/${OE_CONFIG_FILE_NAME}"
    sudo su root -c "printf 'db_port = False\n' >> /etc/${OE_CONFIG_FILE_NAME}"
    sudo su root -c "printf 'db_password = False\n' >> /etc/${OE_CONFIG_FILE_NAME}"

    sudo su root -c "printf 'logfile=/var/log/odoo/odoo.log\n' >> /etc/${OE_CONFIG_FILE_NAME}"

    if [ "$IS_ENTERPRISE" == "True" ]; then
        sudo su root -c "printf 'addons_path=${OE_HOME}/enterprise/addons,${OE_HOME}/addons\n' >> /etc/${OE_CONFIG_FILE_NAME}"
    else
        sudo su root -c "printf 'addons_path=${OE_HOME}/addons\n' >> /etc/${OE_CONFIG_FILE_NAME}"
    fi
    
    
    sudo chown $OE_USER:$OE_USER /etc/${OE_CONFIG_FILE_NAME}
    sudo chmod 640 /etc/${OE_CONFIG_FILE_NAME}
}
function S_9_CreateNginxConfForOdoo()
{
      cat <<EOF > ~/odoo
        upstream odoo {
            server 127.0.0.1:$OE_PORT weight=1 fail_timeout=0;
        }

        upstream odoo-im {
            server 127.0.0.1:$OE_PORT_CHAT weight=1 fail_timeout=0;
        }
EOF
    if [ "$OE_NGINX" == "Nginx for Odoo in port 80 or 443[Yes]" ];then
        cat <<EOF >> ~/odoo
        server {
        
            listen 80;

            # set proper server name after domain set
            server_name $WEBSITE_NAME;
            return 301 https://\$server_name\$request_uri;
        }
EOF
    else

    
cat <<EOF >> ~/odoo
        server {
        
            listen 80;

            # set proper server name after domain set
            server_name $WEBSITE_NAME;

            # Add Headers for odoo proxy mode
            proxy_set_header X-Forwarded-Host \$host;
            proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto \$scheme;
            proxy_set_header X-Real-IP \$remote_addr;
            add_header X-Frame-Options "SAMEORIGIN";
            add_header X-XSS-Protection "1; mode=block";
            proxy_set_header X-Client-IP \$remote_addr;
            proxy_set_header HTTP_X_FORWARDED_HOST \$remote_addr;

            #   odoo    log files
            access_log  /var/log/nginx/$OE_USER-access.log;
            error_log       /var/log/nginx/$OE_USER-error.log;

            #   increase    proxy   buffer  size
            proxy_buffers   16  64k;
            proxy_buffer_size   128k;

            proxy_read_timeout 900s;
            proxy_connect_timeout 900s;
            proxy_send_timeout 900s;

            #   force   timeouts    if  the backend dies
            proxy_next_upstream error   timeout invalid_header  http_500    http_502
            http_503;

            types {
                text/less less;
                text/scss scss;
            }

            #   enable  data    compression
            gzip    on;
            gzip_min_length 1100;
            gzip_buffers    4   32k;
            gzip_types  text/css text/less text/plain text/xml application/xml application/json application/javascript application/pdf image/jpeg image/png;
            gzip_vary   on;
            client_header_buffer_size 4k;
            large_client_header_buffers 4 64k;
            client_max_body_size 0;

            location / {
                proxy_pass  http://odoo;
                # by default, do not forward anything
                # proxy_redirect off;
            }

            location /longpolling {
                proxy_pass http://odoo-im;
            }

            location ~* .(js|css|png|jpg|jpeg|gif|ico)$ {
                expires 2d;
                proxy_pass  http://odoo;
                add_header Cache-Control "public, no-transform";
            }

            # cache some static data in memory for 60mins.
            location ~ /[a-zA-Z0-9_-]*/static/ {
                proxy_cache_valid 200 302 60m;
                proxy_cache_valid 404      1m;
                proxy_buffering    on;
                expires 864000;
                proxy_pass    http://odoo;
            }
        }
EOF
    fi
    if [ OE_NGINX_SSL=="True" ];then
    cat << EOF >>~/odoo
    server {
        listen      443 ssl;
        server_name erp.2rails.cn;
        ssl_certificate $CURDIR/ssl/$WEBSITE_NAME.pem;
        ssl_certificate_key $CURDIR/ssl/$WEBSITE_NAME.key;
        ssl_session_timeout 5m;
        ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_prefer_server_ciphers on;

        root        /usr/share/nginx/html;
        index       index.html index.htm;
        
        # log files
        access_log  /var/log/nginx/$WEBSITE_NAME-access.log;
        error_log   /var/log/nginx/$WEBSITE_NAME-error.log;
    
        # proxy buffers
        proxy_buffers 16 64k;
        proxy_buffer_size 128k;
        # set headers
        proxy_set_header X-Forwarded-Host \$host;
        proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto \$scheme;
        proxy_set_header X-Real-IP \$remote_addr;
        ## default location ##
        location / {
            proxy_pass  http://odoo;
            # force timeouts if the backend dies
            proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504;
            #proxy_redirect off;
            proxy_read_timeout 300000;
        
            
        }
    
        # cache some static data in memory for 60mins
        location ~* /web/static/ {
            proxy_cache_valid 200 60m;
            proxy_buffering on;
            expires 864000;
            proxy_pass http://odoo;
        }
    
        location /longpolling {
            proxy_connect_timeout       600; 
            proxy_send_timeout          600;
            proxy_read_timeout          600;
            send_timeout                600;

            proxy_pass http://odoo-im;

        }
    }
EOF
  fi
  sudo mv ~/odoo /etc/nginx/sites-available/$WEBSITE_NAME
  sudo ln -s /etc/nginx/sites-available/$WEBSITE_NAME /etc/nginx/sites-enabled/$WEBSITE_NAME
  sudo rm /etc/nginx/sites-enabled/default
  sudo service nginx reload
  sudo su root -c "printf 'proxy_mode=True\n' >> /etc/${OE_CONFIG}.conf"
  sudo su root -c "printf 'workers = 3\n' >> /etc/${OE_CONFIG}.conf"
  echo "Done! The Nginx server is up and running. Configuration can be found at /etc/nginx/sites-available/$WEBSITE_NAME"
}
function CreateService()
{
    cat << EOF >~/odoo.service
    [Unit]
    Description=odoo15
    Requires=postgresql.service
    After=network.target postgresql.service

    [Service]
    Type=simple
    SyslogIdentifier=odoo15
    PermissionsStartOnly=true
    User=$OE_USER
    Group=$OE_USER
    ExecStart=python3 $OE_HOME/odoo-bin -c /etc/$OE_CONFIG_FILE_NAME
    StandardOutput=journal+console

    [Install]
    WantedBy=multi-user.target

EOF
    sudo mv ~/odoo.service /etc/systemd/system/odoo.service
    sudo sudo systemctl daemon-reload
    sudo systemctl enable --now odoo.service
    sudo systemctl start odoo.service
}
 

#--------------------------------------------------
# 安装其它常用依赖，用odoo的deb安装已经默认安装大部分
#--------------------------------------------------
function S_4_InstallBase()
{
    _p "\e[1;31m系统升级....\e[0m"
    sudo apt-get update
    sudo apt-get upgrade -y
    
    _p "\n---- Installing nodeJS NPM and rtlcss for LTR support ----"
    sudo apt-get install nodejs npm -y
    sudo npm install -g rtlcss less
    sudo apt-get install libpcre3 libpcre3-dev 
    sudo apt-get install libtool 
    sudo apt-get install gcc-c++ 
    sudo apt-get install openssl libssl-dev libperl-dev
    # sudo apt install gdebi-core #如果要使用 gdebi 命令需要安装这个

    #--------------------------------------------------
    # Install Dependencies
    #--------------------------------------------------
    _p "\n--- Installing Python 3 + pip3 【安装py3和pip3】 --"
    sudo apt install git python3-pip build-essential wget python3-dev python3-venv  python3-wheel libfreetype6-dev libxml2-dev libzip-dev libldap2-dev libsasl2-dev python3-setuptools node-less libjpeg-dev zlib1g-dev libpq-dev  libxslt1-dev libldap2-dev libtiff5-dev libjpeg8-dev libopenjp2-7-dev liblcms2-dev libwebp-dev libharfbuzz-dev libfribidi-dev libxcb1-dev -y



    # _p "\n---- Install python packages/requirements 【安装odoo${OE_VERSION}系统需求库】----"
    # sudo -H pip3 install -r https://github.com/odoo/odoo/raw/${OE_VERSION}/requirements.txt

      
    #--------------------------------------------------
    # 安装 Wkhtmltopdf
    #--------------------------------------------------
    if [ $INSTALL_WKHTMLTOPDF="True" ];
    then
        _p "\n---- Install wkhtml and place shortcuts on correct place for ODOO ----"
        #pick up correct one from x64 & x32 versions:
        if [ "`getconf LONG_BIT`" == "64" ];
        then
            _url=$WKHTMLTOX_X64
        else
            _url=$WKHTMLTOX_X32
        fi
        _wxfilename=`basename $_url`
        if [ ! -e $_wxfilename ];then
            _p "$_wxfilename文件不存在，正在下载..." 31 2
            sudo wget $_url
        fi 
        sudo dpkg -i  $_wxfilename 
        sudo ln -f -s /usr/local/bin/wkhtmltopdf /usr/bin
        sudo ln -f -s /usr/local/bin/wkhtmltoimage /usr/bin

        #安装中文字体 
        sudo apt-get install ttf-wqy-zenhei #安装中文字体（正黑） 
        sudo apt-get install ttf-wqy-microhei #安装中文字体（微软雅黑） 

    else
      echo "Wkhtmltopdf isn't installed due to the choice of the user!"
    fi 
}
#--------------------------------------------------
# 安装 PostgreSQL Server 14, 13, 12
#--------------------------------------------------
RETRY_PG="False"
function S_5_InstallPg()    {

    if [ "$OE_PG" != 'None' ];
    then
        _p "\n---- Prepare Install $OE_PG ----"

        if [  "$U_Version"=='20' &&  "$OE_PG" != 'Postgresql 12.x [Recommend. OS default]' ];then
            _p "当前系统默认支持Postgresql 12,您选择的是$OE_PG,需要配置下载方式key"
            sudo apt-get install curl ca-certificates -y
            sudo apt-get install -y wget ca-certificates
            sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
            sudo wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

            _p "\n---- Installing Postgresql Server ----"
            sudo apt-key update
            sudo apt-get update
        fi
    fi

    if [ "$OE_PG" == 'Postgresql 14' ];
    then
        sudo apt-get install postgresql-14 -y
    fi
 
    if [ "$OE_PG" == 'Postgresql 13' ];
    then
        sudo apt-get install postgresql-13 -y
    fi

    if [ "$OE_PG" == 'Postgresql 12.x [Recommend. OS default]'  ];
    then
        sudo apt-get install postgresql -y
        # sudo apt-get install postgresql-contrib -y
    fi
    if command -v psql >/dev/null 2>&1; then 
        _p "$OE_PG安装成功"
    else 
        if [ "$RETRY_PG"=='False' ];then
            RETRY_PG="True"
            _p "$OE_PG 安装出错...,正在尝试修复安装"
            sudo apt --fix-broken install
            S_5_InstallPg
        fi
    fi

    sudo su - postgres -c "createuser -s $OE_USER" 2> /dev/null || true
    
    #ALTER ROLE odoo WITH Superuser Createrole CreateDB Replication BypassRLS;
    # sudo su - postgres -c "ALTER ROLE ${OE_USER} WITH Superuser Createrole CreateDB Replication BypassRLS;"   2> /dev/null || true

}

#--------------------------------------------------
# 安装odoo
#--------------------------------------------------
function S_6_InstallOdoo()    {
    if [ "$OE_TYPE" != 'None' ];
    then
        _p "\n==== 正在安装 $OE_TYPE===="
    fi

    if [ "$OE_TYPE" == 'odoo15 github 社区版' ];
    then
        sudo git clone --depth 1 --branch $OE_VERSION https://gitee.com/mirrors/odoo.git $OE_HOME/
        if [ ! -e $OE_HOME/odoo-bin ];then
            while true
            do
                read -r -p "github clone 失败,是否切换到国外github镜像尝试一下? [Y/n] " input 
                case $input in
                    [yY][eE][sS]|[yY])
                            sudo git clone --depth 1 --branch $OE_VERSION https://github.com/odoo/odoo.git $OE_HOME/
                            break
                            ;;
                    [nN][oO]|[nN])
                            echo "本次安装到此结束"
                            exit 1
                            ;;
                    *)
                            echo "无效输入..." 
                            ;;
                esac
            done 
        fi
        _p "odoo 克隆完成...安装 pip -r requirements.txt\n"
        # 再安装一次 requirements.txt
        sudo -H pip install -r ./odoo$OE_VERSION/requirements.txt
    fi

    if [ "$OE_TYPE" == 'Odoo 15 Community from odoo.com 远程社区版deb安装包' ];
    then
        sudo wget $OE_COMMUNITY_LATEST_15 -O odoo_15.0.latest_all.deb
        _p "odoo_15.0.latest_all.deb下载完成，正在安装 odoo_15.0.latest_all.deb...\n"
        sudo gdebi --n `basename $OE_COMMUNITY_LATEST`
    fi
    if [ "$OE_TYPE" == 'Odoo 15 Community from local[odoo_15.0.latest_all.deb] 本地社区版' ];
    then
        if [ -e $CURDIR/odoo_15.0.latest_all.deb ];then
            sudo dpkg -i $CURDIR/odoo_15.0.latest_all.deb 
            sudo apt-get -f -y install
        else
            _p "$CURDIR/odoo_15.0.latest_all.deb 文件不存在！请检查"
            exit 0
        fi
    fi
    if [ "$OE_TYPE" == 'Odoo 15 Enterprise from local[odoo_15.0+e.latest_all.deb] 本地企业版' ];
    then
        if [ -e $CURDIR/odoo_15.0+e.latest_all.deb ];then
            sudo dpkg -i $CURDIR/odoo_15.0+e.latest_all.deb
            sudo apt-get -f -y install
        else
            _p "$CURDIR/odoo_15.0+e.latest_all.deb 文件不存在！请检查"
            exit 0
        fi
    fi

    if [ "$OE_TYPE" != 'None' ];
    then
        # 下载个性化配置文件，将odoo用户加至管理组（方便，如有更高安全要求可另行处理）
    
        sudo usermod -a -G root $OE_USER
        # 处理附加模块, npm
        sudo apt-get install npm -y
        sudo npm -g install npm
        sudo npm install npm@latest -g
        sudo npm install -g n
        sudo n latest
        sudo n stable
        sudo n lts
        sudo npm install -g postcss
         
         
        sudo mkdir /var/log/odoo
        sudo chown -R $OE_USER:root /var/log/odoo
        sudo chmod 770 /var/log/odoo

    fi

}
#--------------------------------------------------
# 安装 Nginx 作为 web 转发，启用 polling
#--------------------------------------------------
function S_8_InstallNg()    {
    if [ "$OE_NGINX" == 'Nginx for Odoo in port 80 or 443[Yes]' ];
    then
        _p "\n---- Prepare Install $OE_NGINX ----" 
        sudo apt-get install nginx -y
        if [ -f /etc/nginx/nginx.conf ];then
            S_9_CreateNginxConfForOdoo
            _p "\n---- Nginx Done ----" 32
        else
            _p "nginx 安装出错...,正在尝试修复安装"
            sudo apt --fix-broken install
            sudo apt-get install nginx -y
            if [ -f /etc/nginx/nginx.conf ];then
                S_9_CreateNginxConfForOdoo
                _p "\n---- Nginx Done 修复安装完成 ----" 32
            else
                _p "\n------Nginx 未知原因安装失败，请检查------"
            fi
        fi
        #sudo wget -x -q $OE_NGINX_CONF_FILE -O /etc/nginx/nginx.conf sudo nginx -s reload
        
    fi
}
#--------------------------------------------------
# 设置重启脚本，完成安装
#--------------------------------------------------
function InstallDone()    {
    # sudo rm $CURDIR/r.sh
    # sudo touch $CURDIR/r.sh
    # sudo sh -c 'echo "#!/usr/bin/env bash" > $CURDIR/r.sh'
    # sudo sh -c 'echo "sudo systemctl restart postgresql && sudo rm /var/log/odoo/*.log && sudo systemctl restart odoo" >> $CURDIR/r.sh'
    # sudo sh -c 'echo "sudo systemctl status postgresql && sudo systemctl status odoo" >> $CURDIR/r.sh'
    # sudo chmod +x r.sh

    _p "* $OE_TYPE Install Done"
    _p "postgresql版本类型: $OE_PG"
    _p "odoo Port: $OE_PORT" 32
    _p "User service: $OE_USER" 32
    _p "User PostgreSQL: $OE_USER" 32
    _p "Code location: $OE_HOME" 32
    _p "重启odoo服务:   sudo systemctl restart odoo.service" 33
    _p "查看odoo状态:   sudo systemctl status odoo.service" 33
    _p "停止odoo服务:   sudo systemctl stop odoo.service" 33
    _p "odoo 配置文件名:    /etc/$OE_CONFIG_FILE_NAME" 35   
    _p "nginx 配置文件名:   /etc/nginx/sites-available/$WEBSITE_NAME" 35   
    _p "systemd service 配置文件名:/etc/systemd/system/odoo.service" 35   
    if [ "$OE_NGINX" == 'Nginx for Odoo in port 80 or 443[Yes]' ];then
        if [ "$OE_NGINX_SSL" == 'True' ];then
            _p "已启用nginx并使用ssl,访问odoo系统使用 https://$WEBSITE_NAME"
        else
            _p "已启用nginx ,访问odoo系统使用 http://$WEBSITE_NAME"
        fi
    else
        _p "未启用nginx,访问odoo系统使用 http://$WEBSITE_NAME:$OE_PORT"
    fi
    
    echo "-----------------------------------------------------------"
    if [ $OE_NGINX_SSL=="True" ];
    then
        if [ ! -e $CURDIR/ssl/$WEBSITE_NAME.pem  ];then
            _p "$CURDIR/ssl/$WEBSITE_NAME.pem 不存在,请上传"
        fi
        if [ ! -e $CURDIR/ssl/$WEBSITE_NAME.key ];then
            _p "$CURDIR/ssl/$WEBSITE_NAME.key 不存在，请上传"
        fi
    fi
    _p "现在查看odoo.service状态，按q返回"
    sudo systemctl status odoo.service

    EnterpriseZipFile=$(ls -F . | grep  -E "odoo[0-9]{2}e.*\.zip")
    if [ "$EnterpriseZipFile"!='' ];then
        _p "${EnterpriseZipFile} 看上去像企业版压缩包，如果要安装，请使用命令 unzip ${EnterpriseZipFile} -d ${OE_HOME} " 34
        _p "再重新启动ODOO服务 sudo systemctl restart odoo.service 便可" 34
    fi
}

#--------------------------------------------------
# 执行安装
#--------------------------------------------------


S_1_ConfirmOdoo

_p "\e[1;31m当前目录:${CURDIR} 要安装的ODOO版本号:${OE_VERSION} 要安装的版本类型:${OE_TYPE}\e[0m"
if [ "${OE_TYPE}"!="None(and Exit)" ];
then
    S_2_ConfirmPg
    S_3_ConfirmNg
    S_4_InstallBase
    S_5_InstallPg
    S_6_InstallOdoo
    S_7_CreateOdooConf
    S_8_InstallNg
    CreateService
    InstallDone
else
    _p "您选择退出安装${OE_TYPE}=None(and Exit),现在退出。"
    exit 0
fi

